/*
 * jxUtils Project (2013, 2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxUtils.image.filter;

import java.awt.Color;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import org.jxUtils.image.ImageUtil;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxUtils
 * @package org.jxUtils.image.filter
 * @date 04/08/2014 - 21:05:55
 */
public final class NegativeFilter {
	
	/**
	 * @param bufferedImage
	 * @return Negative {@link ImageIcon} to bufferedImage
	 */
	public static ImageIcon apply(final BufferedImage bufferedImage) {
	
		final BufferedImage newBufferedImage = ImageUtil.copy(bufferedImage);
		
		int[] rgb = new int[3];
		
		//
		for(int column = 0; column < bufferedImage.getWidth(); column++) {

			// 
			for(int line = 0; line < bufferedImage.getHeight(); line++) {
				
				rgb = bufferedImage.getRaster().getPixel(column, line, rgb);
				
				rgb[0] = 255 - rgb[0];
				rgb[1] = 255 - rgb[1];
				rgb[2] = 255 - rgb[2];
				
				newBufferedImage.getRaster().setPixel(column, line, rgb);
			}
		}
		
		return new ImageIcon(newBufferedImage);
	}
	
	/**
	 * @param color
	 * @return Negative {@link Color} to color
	 */
	public static Color apply(final Color color) {
	
		return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
	}
}
